<template>
  <div class="container" style="padding: 0;margin: 0;">
    <div class="flex-col full">
      <div class="w_full">
        <div class="w_full flex-row-center space-between">
          <el-button link class="back_title" @click="click_back" :icon="Back">返回人员管理列表</el-button>

          <el-button style="width:114px;height: 48px;border-radius: 12px" type="primary" :icon="Edit"
                     @click="click_edit">编辑
          </el-button>
        </div>
      </div>
      <div class="flex_1 flex-row comm_border" style="margin-top: 16px">
        <div class="flex-col-center" style="width: 400px; margin-top: 64px;">
          <el-image v-if="data.userInfo.gender=='01'" class="user_image" :src="require('@/assets/man.png')"></el-image>
          <el-image v-else-if="data.userInfo.gender=='02'" class="user_image" :src="require('@/assets/women.png')"></el-image>
          <el-image v-else class="user_image" :src="require('@/assets/unknown_gender.png')"></el-image>
          <div class="user_userName">{{ data.userInfo.userName }}</div>
          <div class="user_userId">{{ data.userInfo.userId }}</div>
        </div>
        <div class="flex-col " style="width: 400px;;">
          <div class="flex-col">
            <div class="flex-row" style="margin-top: 64px">
              <div class="user_title_rec"></div>
              <div class="user_title">基本信息</div>
            </div>
            <div class="user_content" style="margin-top: 24px; margin-left: 50px;">
              <el-form label-position="left"
                       :model="data" label-width="100px"
                       ref="form"
                       style="margin: 10px; width: auto"
              >
                <el-form-item class="form_item" prop="qtType" label="性别">
                  <div class="user_data">{{ data.userInfo.genderStr }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="联系方式">
                  <div class="user_data">{{ data.userInfo.phoneNum }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="身份证号">
                  <div class="user_data">{{ data.userInfo.identityCard }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="毕业院校">
                  <div class="user_data">{{ data.userInfo.college }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="教育背景">
                  <div class="user_data">{{ data.userInfo.education }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="参加工作时间">
                  <div class="user_data">{{ data.userInfo.workingDateStr }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="工作年限">
                  <div class="user_data">{{ data.userInfo.workingYear }}</div>
                </el-form-item>
              </el-form>
            </div>

            <div class="flex-row" style="margin-top: 64px">
              <div class="user_title_rec"></div>
              <div class="user_title">基本信息</div>
            </div>
            <div class="user_content" style="margin-top: 24px;margin-left: 50px;">
              <el-form label-position="left"
                       :model="data"
                       ref="form" label-width="100px"
                       style="margin: 10px; width: auto"
              >
                <el-form-item class="form_item" prop="qtType" label="岗位">
                  <div class="user_data">{{ data.userInfo.positionStr }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="职称">
                  <div class="user_data">{{ data.userInfo.titleStr }}</div>
                </el-form-item>
                <el-form-item class="form_item" prop="qtType" label="能级">
                  <div class="user_data">{{ data.userInfo.workLevelStr }}</div>
                </el-form-item>
              </el-form>
            </div>

          </div>

        </div>


      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {onMounted, reactive, shallowRef} from "vue";
import {Back, Edit} from "@element-plus/icons-vue";
import {addDialog} from "@/components/gDialog/index";
import msg from "@/components/msg";
import {DictInfoVO} from "@/type/vo/DictInfoVO";
import {api_getListUser} from "@/request/apis/userApi";
import {UserQueryDto} from "@/type/dto/UserQueryDto";
import {UserInfoVO} from "@/type/vo/UserInfoVO";
import UserCreate from "@/views/User/Dialogs/UserCreate.vue";
import {useRoute} from "vue-router";
import {DICT_TYPE_LEVEL, DICT_TYPE_POSITION, DICT_TYPE_TITLE} from "@/constants/Constants_DictType";
import {api_getListDict} from "@/request/apis/assistantApi";
import router from "@/router";
import {diffDay, diffDYear, tickAsTimeString} from "@/utils/TimeUtil";
import {GenderAsString} from "@/utils/EnumHelper";
import UserInfoHelper from "@/type/utils/UserInfoHelper";


const route = useRoute();

console.log('route', route);
console.log('route.query', route.query);
console.log('route.params', route.params);
const userIdPara = route.query.userId as string;

const data = reactive({
  userId: userIdPara,
  userInfo: {} as UserInfoVO,
  listTitle: Array<DictInfoVO>(),
  listLevel: Array<DictInfoVO>(),
  listPosition: Array<DictInfoVO>(),
})

onMounted(async () => {
  await queryDict(DICT_TYPE_TITLE);
  await queryDict(DICT_TYPE_LEVEL);
  await queryDict(DICT_TYPE_POSITION);
  await search_pri();
})

const queryDict = async (dictType: string) => {
  let r = await api_getListDict(dictType);
  if (!r) {
    await msg.error("数据异常");
    return;
  }
  if (r.code != 0) {
    await msg.error(`数据异常${r.code} msg：${r.msg}`);
    return;
  }
  switch (dictType) {
    case DICT_TYPE_TITLE:
      data.listTitle = r.data;
      break;
    case DICT_TYPE_LEVEL:
      data.listLevel = r.data;
      break;
    case DICT_TYPE_POSITION:
      data.listPosition = r.data;
      break;
  }
}

const click_back = () => {
  router.back();
}
const click_edit = () => {
  try {
    addDialog({
      title: "编辑用户",
      component: shallowRef(UserCreate),
      width: "800px",
      props: {
        userInfo: data.userInfo,
        editFlag: true
      },
      callBack: async (dRet: boolean) => {
        await search_pri();
      }
    })
    // 处理确认操作
  } catch (error) {
    // 处理取消操作
  }
}


const search_pri = async () => {

  const limit = 10;
  const page = 1;
  const query: UserQueryDto = {
    limit: limit,
    page: page,
    userId: userIdPara
  }

  const r = await api_getListUser(query);
  if (!r) {
    await msg.info('数据异常');
    return;
  }
  if (r.code != 0) {
    await msg.info(`数据异常!  ${r.code} msg：${r.msg}`);
    return;
  }
  if (r.data != undefined) {
    console.log('r.data.records', r.data.records);
    if (r.data.records) {
      for (let i = 0; i < r.data.records.length; i++) {
        r.data.records[i].index = i + 1;
      }
    }
    data.userInfo = r.data.records[0];
    UserInfoHelper.init(data.userInfo);
    UserInfoHelper.initLevel(data.userInfo,data.listLevel);
    UserInfoHelper.initTitle(data.userInfo,data.listTitle);
    UserInfoHelper.initPosition(data.userInfo,data.listPosition);
  }
}

const click_search = async () => {
  await search_pri();
};

const handleSizeChange = async (val: number) => {
  await search_pri();
}
const handleCurrentChange = async (val: number) => {
  await search_pri();
}

</script>

<style scoped>
.user_image {
  width: 150px;
  height: 150px;

}

.user_userName {
  font-size: 24px;
  font-weight: 600;
  color: #0A1629;
  line-height: 28px;
  margin-top: 32px;
}

.user_userId {
  font-size: 16px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  line-height: 24px;
  margin-top: 16px;
}

.user_title_rec {
  width: 4px;
  height: 28px;
  background: #3F8CFF;
  border-radius: 2px 2px 2px 2px;
  opacity: 1;
}

.user_title {
  font-size: 20px;
  font-weight: 400;
  color: #0A1629;
  line-height: 23px;
  margin-left: 8px;
}

.form_item {
  margin-top: 16px;
}


.grid-container {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.row {
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-1,
.row-3 {
}

.row-2 {
  overflow: auto;
}

.scrollable-content {

  line-height: 1.5em;
}


.title {
  font-size: 24px;
  font-weight: 600;
  color: #0A1629;
  line-height: 28px;
}

.back_title {
  font-size: 16px;
  font-weight: 600;
  color: #3F8CFF;
  line-height: 19px;
}

.user_data {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  margin-left: 16px;
}

.date-picker {
  height: 48px;
  color: black;
  background: #FFFFFF;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  border: 1px solid #DCDCDC;
}

.el-scrollbar__view {
  height: calc(100% - 100px); /* 根据实际情况调整高度 */
}

.infinite-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.infinite-list .infinite-list-item {
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
  margin: 10px;
  color: var(--el-color-primary);
  overflow: hidden;
}

.infinite-list .infinite-list-item + .list-item {
  margin-top: 10px;
}

.naireName {
  font-size: 20px;
  font-weight: 400;
  color: #0A1629;
  line-height: 24px;
}


</style>

